﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace EFCore一对多关系配置
{
  public class CommentConfig : IEntityTypeConfiguration<Comment>
  {
    public void Configure(EntityTypeBuilder<Comment> builder)
    {
      builder.ToTable("T_Comment");
      builder.Property(a => a.Message).IsUnicode().IsRequired();
      builder.HasOne<Article>(c => c.TheArticle).WithMany(a => a.Comments).HasForeignKey(a=>a.TheArticleId).IsRequired();
    }
  }
}
